﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.EmpbasicService;

namespace CommunitySystem.PageView
{
    public partial class BianZhi_GuoDuXingWindow : ChildWindow
    {
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        public BianZhiModel BianZhiModels =
            new BianZhiModel();
        public int KeShiID;
        public string KeShiName;
        public string ZhengFuKe;
        public string ZhengFuKe1;
        public bool IsNew = false;
        public BianZhi_GuoDuXingWindow(int keshiid,BianZhiModel model,string type,bool isnew)
        {
            InitializeComponent();
            KeShiID = keshiid;
            BianZhiModels = model;
            IsNew = isnew;
            if (type == "正科借用") ZhengFuKe = "正科";
            if (type == "副科借用") ZhengFuKe = "副科";
            if (type == "主任借用") ZhengFuKe = "主任";
            if (type == "副主任借用") ZhengFuKe = "副主任";
            ZhengFuKe1 = type;
            Client.UpdateBianZhiDetail_JieYongModelCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(Client_UpdateBianZhiDetail_JieYongModelCompleted);
            Client.GetChaoZhiShuCompleted += new EventHandler<EmpbasicService.GetChaoZhiShuCompletedEventArgs>(Client_GetChaoZhiShuCompleted);
            Client.GetChaoZhiShuAsync(keshiid, ZhengFuKe);
        }

        void Client_UpdateBianZhiDetail_JieYongModelCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("过渡性超职成功！");
            this.DialogResult = true;
        }

        void Client_GetChaoZhiShuCompleted(object sender, EmpbasicService.GetChaoZhiShuCompletedEventArgs e)
        {
            guoduxing.Text = e.Result;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if(!string.IsNullOrEmpty(guoduxing.Text))
            {
                Client.UpdateBianZhiDetail_JieYongModelAsync(KeShiID.ToString(), ZhengFuKe1, BianZhiModels, 1, guoduxing.Text, IsNew);
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private string pattern = @"^[0-9]+([.]{1}[0-9]+){0,1}$";
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            Match m = Regex.Match(((TextBox)sender).Text, pattern); // 匹配正则表达式
            if (!m.Success) // 输入的不是数字
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("只能输入数字！");
                ((TextBox)sender).Text = "";
                return;
            }
        }
    }
}
